import request from "@/utils/request";
import {
  PersonBankEditForm,
  PayrollEditForm,
  AuditForm,
  PayrollDetailEditForm,
  ProjectCorpWageAuthEditForm,
  WagePayrollAuthQuery,
} from "./types";
const currentSystem = localStorage.getItem("usertypeName");

/**
 * 获取人员银行信息列表
 */
export function getPersonBankList(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/personbank/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/personbank/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/personbank/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/personbank/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/personbank/page`;
      break;
    default:
      url = `/api/v1/sysuser/personbank/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取人员银行信息
 */
export function getPersonBankInfo(id: number, corpId: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/personbank/${id}/form`;
      break;
    case "Corp":
      url = `/api/v1/corp/personbank/${id}/form`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/personbank/${id}/form`;
      break;
    case "Manager":
      url = `/api/v1/manager/personbank/${id}/form`;
      break;
    case "Commander":
      url = `/api/v1/commander/personbank/${id}/form`;
      break;
    default:
      url = `/api/v1/sysuser/personbank/${id}/form`;
  }
  return request({
    url: url,
    method: "get",
    params: { corpId: corpId },
  });
}

/**
 * 新增人员银行信息
 */
export function addPersonBank(data: PersonBankEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/personbank/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/personbank/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/personbank/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/personbank/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/personbank/create`;
      break;
    default:
      url = `/api/v1/sysuser/personbank/create`;
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 修改人员银行信息
 */
export function editPersonBank(id: number, data: PersonBankEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/personbank/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/personbank/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/personbank/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/personbank/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/personbank/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/personbank/${id}`;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 删除人员银行信息
 */
export function deletePersonBank(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/personbank/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/personbank/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/personbank/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/personbank/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/personbank/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/personbank/${id}`;
  }
  return request({
    url: url,
    method: "delete",
  });
}
///导出选中的人员工资卡模板
export function exportCheckedBankTemp(data: any) {
  let url = "/api/v1/manager/personbank/exportCheckedBankTemp";

  return request({
    url: url,
    method: "post",
    responseType: "arraybuffer",
    data: data,
  });
}
/**
 * 银行信息下拉列表
 */
export function getPersonBankPullDownList(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/personbank/pulldown`;
      break;
    case "Corp":
      url = `/api/v1/corp/personbank/pulldown`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/personbank/pulldown`;
      break;
    case "Manager":
      url = `/api/v1/manager/personbank/pulldown`;
      break;
    case "Commander":
      url = `/api/v1/commander/personbank/pulldown`;
      break;
    default:
      url = `/api/v1/sysuser/personbank/pulldown`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 创建工资单
 */
export function CreatePayroll(data: PayrollEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/create`;
      break;

    case "Manager":
      url = `/api/v1/manager/payroll/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/create`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/create`;
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 修改工资单
 */
export function UpdatePayroll(data: PayrollEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/${data.id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/${data.id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/${data.id}`;
      break;

    case "Manager":
      url = `/api/v1/manager/payroll/${data.id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/${data.id}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/${data.id}`;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 获取工资单表单
 */
export function GetPayrollForm(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/${id}/form`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/${id}/form`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/${id}/form`;
      break;

    case "Manager":
      url = `/api/v1/manager/payroll/${id}/form`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/${id}/form`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/${id}/form`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取工资单列表(分页)
 */
export function QueryPayrollPage(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/page`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 删除工资单
 */
export function DeletePayroll(ids: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/${ids}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/${ids}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/${ids}`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/${ids}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/${ids}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/${ids}`;
  }
  return request({
    url: url,
    method: "delete",
  });
}

/**
 * 提交工资单
 */
export function SubmitPayroll(id: number, attachments: Array<any>) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/submit/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/submit/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/submit/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/submit/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/submit/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/submit/${id}`;
  }
  return request({
    url: url,
    method: "post",
    data: { attachments },
  });
}

/**
 * 获取工资单审核记录
 */
export function QueryAuditLogs(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/auditLogs`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/auditLogs`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/auditLogs`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/auditLogs`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/auditLogs`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/auditLogs`;
  }
  return request({
    url: url,
    method: "get",
    params: { id: id },
  });
}

/**
 * 审核工资单
 */
export function AuditPayroll(id: number, data: AuditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/audit/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/audit/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/audit/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/audit/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/audit/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/audit/${id}`;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 获取工资单明细
 */
export function PayrollDetail(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/details/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/details/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/details/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/details/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/details/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/details/${id}`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 导出工资明细模板
 */
export function ExportPayrollTemplate(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/exportTemplate/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/exportTemplate/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/exportTemplate/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/exportTemplate/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/exportTemplate/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/exportTemplate/${id}`;
      break;
  }

  return request({
    url: url,
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 导出工资明细
 */
export function ExportPayrollDetail(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/exportDetails/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/exportDetails/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/exportDetails/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/exportDetails/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/exportDetails/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/exportDetails/${id}`;
      break;
  }
  return request({
    url: url,
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 新增工资单明细
 */
export function AddPayrollDetail(id: number, data: PayrollDetailEditForm[]) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/addPayrollDetails/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/addPayrollDetails/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/addPayrollDetails/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/addPayrollDetails/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/addPayrollDetails/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/addPayrollDetails/${id}`;
      break;
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 工资查询
 */
export function QueryPageSalaryInquiry(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/page_salaryInquiry`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/page_salaryInquiry`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/page_salaryInquiry`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/page_salaryInquiry`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/page_salaryInquiry`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/page_salaryInquiry`;
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 项目公司工资权限
 */
export function QueryProjectCorpWageAuth(data: any) {
  return request({
    url: `/api/v1/sysuser/projectCorpWageAuth/page`,
    method: "get",
    params: data,
  });
}

/**
 * 获取项目公司工资权限表单
 */
export function GetProjectCorpWageAuthForm(id: number) {
  return request({
    url: `/api/v1/sysuser/projectCorpWageAuth/${id}/form`,
    method: "get",
  });
}
/**
 * 创建项目公司工资权限
 */
export function CreateProjectCorpWageAuth(data: ProjectCorpWageAuthEditForm) {
  return request({
    url: `/api/v1/sysuser/projectCorpWageAuth/create`,
    method: "post",
    data: data,
  });
}

/**
 * 更新项目公司工资权限
 */
export function UpdateProjectCorpWageAuth(id: number, data: ProjectCorpWageAuthEditForm) {
  return request({
    url: `/api/v1/sysuser/projectCorpWageAuth/${id}`,
    method: "put",
    data: data,
  });
}

/**
 * 删除项目公司工资权限
 */
export function DeleteProjectCorpWageAuth(id: number) {
  return request({
    url: `/api/v1/sysuser/projectCorpWageAuth/${id}`,
    method: "delete",
  });
}

/**
 * 项目公司工资权限是否存在
 */
export function ExtisWageAuth(data: WagePayrollAuthQuery) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/wage_auth`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/wage_auth`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/wage_auth`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/wage_auth`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/wage_auth`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/wage_auth`;
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 导入提交银行卡
  POST /api/v1/corp/personbank/saveImport
 */
export function AddPersonBankList(data: PersonBankEditForm[]) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/personbank/saveImport`;
      break;
    case "Corp":
      url = `/api/v1/corp/personbank/saveImport`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/personbank/saveImport`;
      break;
    case "Manager":
      url = `/api/v1/manager/personbank/saveImport`;
      break;
    case "Commander":
      url = `/api/v1/commander/personbank/saveImport`;
      break;
    default:
      url = `/api/v1/sysuser/personbank/saveImport`;
      break;
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 创建银行批量代发单
 * @param id
 */
export function CreatePaymentWages(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/payment/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/payment/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/payment/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/payment/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/payment/create`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/payment/create`;
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "put",
  });
}

/**
 * 提交银行批量代发单
 * @param id
 */
export function SubmitPaymentWages(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/payment/submit`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/payment/submit`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/payment/submit`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/payment/submit`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/payment/submit`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/payment/submit`;
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "put",
  });
}

/**
 * 撤销银行批量代发单
 * @param id
 */
export function UnDoPaymentWages(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/payroll/payment/undo`;
      break;
    case "Corp":
      url = `/api/v1/corp/payroll/payment/undo`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/payroll/payment/undo`;
      break;
    case "Manager":
      url = `/api/v1/manager/payroll/payment/undo`;
      break;
    case "Commander":
      url = `/api/v1/commander/payroll/payment/undo`;
      break;
    default:
      url = `/api/v1/sysuser/payroll/payment/undo`;
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "put",
  });
}
